package algorithm.easy;

public class Solution35 {
    //输入: nums = [1,3,5,6], target = 2
    //输出: 1
    public static int searchInsert(int[] nums, int target) {

        int p = 0;
        if(target <nums[0]){
             p =0;
        }
        else if(target >nums[nums.length-1]){
            p = nums.length;
        }else{
            for(int i=1;i<nums.length-1;i++){
                if(nums[i]>target &&  target>nums[i-1]){
                   p = i;
                   break;
                }
            }
        }
        return p;
    }
    public static void main(String[] args){
        int[] nums = {1,3,5,6};
        int target = 7;
        System.out.println(searchInsert(nums,target));
    }

}
